<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{   

    public function __construct(){
        
        parent::__construct();
        $map['id'] = I('get.id','intval');
        $res = M('category')->where($map)->find();
        if(!$res){

            $map['id'] = 1;
            $res = M('category')->where($map)->find();
        }

        if($res['pid'] != 0){
           
            $map['id'] = $res['pid'];
            $logo = M('category')->where($map)->find();
        }else{

            $logo = $res;
        }
        $list = M('category')->where(array('pid'=>$logo['id']))->select();

        foreach($list as $key=>$val){

            $list2[] = $val['id'];
        }
        if(in_array(I('get.id'), $list2)){

            $judge = I('get.id');
        }else{

            $judge = $list[0]['id'];
        }
        foreach($list as $key=>$val){

            if($val['id']==$judge){

                $position=$val;
            }
        }
        $this->assign('logo',$logo);
        $this->assign('list',$list);
        $this->assign('judge',$judge);
        $this->assign('position',$position);
    }
    public function index()
    {
         $this->redirect('Index/category',array('id'=>8));
        $this->display();
    }

    public function header()
    {

        $this->display();
    }
    
    public function footer()
    {

    	$this->display();
    }
    

    public function category()

    {

        
        //如果是图片
        if($this->logo['id']=='5'){
            $img = M('detail')->where(array('pid'=>$this->judge))->select();
            $this->assign('img',$img);
            $this->display('img');

        }elseif($this->logo['id'] =='4'){//如果是新闻
             
            $core = M('detail')->where(array('pid'=>$this->judge))->find();
            $this->assign('core',$core);
            if(count($core)>=1){

                $judge2= 1;
            }
            $this->assign('judge2',$judge2);
            $this->display('core');
        }elseif($this->logo['id'] =='3'){//如果是新闻
             
            $news = M('detail')->where(array('pid'=>$this->judge))->select();
            $this->assign('news',$news);
            if(count($news)>=1){

                $judge2= 1;
            }
            $this->assign('judge2',$judge2);
            $this->display('news');
        }elseif($this->logo['id'] =='2'){

            if($this->judge==8){

                 $this->display('jianjie');
            }elseif($this->judge==10){//发展理念

                 $this->display('develop');
            }elseif($this->judge==9){//组织架构

                 $this->display('jiagou');
           }elseif($this->judge==11){//公司文化

                 $this->display('culture');
            }
        }elseif($this->logo['id'] =='7'){

            if($this->judge==37){//意见箱

                 $this->display('sugges');
            }elseif($this->judge==36){//联系

                 $this->display('contact');
            }elseif($this->judge==35){//联系

                 $this->display('people');
            }
        }elseif($this->logo['id'] =='6'){

            if($this->judge==27){//品牌商
                
                 $co = M('detail')->where(array('pid'=>$this->judge))->select();
                 foreach($co as $key=>$val){

                    $val['list'] = explode(',', trim($val['detail'],','));
                    $co2[] = $val;
                 }

                 $this->assign('co',$co2);
                 $this->display('co_band');
            }else{
                $this->assign('id',$_GET['id']);
                $this->display('co2');
            }
        }else{

            $this->display();
        }
        
    }

    public function news_detail(){

        $map['id'] = I('get.news_id')>0?I('get.news_id'):exit('none');
        $detail = M('detail')->where($map)->find();
        $this->assign('detail',$detail);
        $this->display();
    }
}